package com.itdianzi.controller.base;

import com.itdianzi.domain.system.User;
import com.itdianzi.service.company.CompanyService;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class BaseController {

    /*父类controller 目的: 给其他提供一些常用参数*/
    @Autowired
    public HttpServletRequest request;
    @Autowired
    public HttpSession session;
    @Autowired
    public HttpServletResponse response;//报错不管 代码可以运行 idea的解析问题

    //企业id 和企业名称 以后从登录的用户中获得
    public String companyId;
    public String companyName;

    public User loginUser;

    /**
     * @ModelAttribute 在执行所有方法之前执行一次
     */
    @ModelAttribute
    public void before() {
        User user = (User) session.getAttribute("loginUser");
        if (user != null) {//解决一些特殊问题
        companyId = user.getCompanyId();
        companyName = user.getCompanyName();
            this.loginUser = user;
        }
    }
}
